package com.aruba.attendance.database.di

import android.app.Application
import androidx.room.Room
import com.aruba.attendance.database.AppDatabase
import com.aruba.attendance.database.dao.OverworkDurationDao
import com.aruba.attendance.database.dao.RecordDao
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

/**
 * 将数据库相关类注入容器
 * Created by aruba on 2023/2/15.
 */
@InstallIn(SingletonComponent::class)
@Module
object DatabaseModule {
    @Singleton
    @Provides
    fun getAppDatabase(application: Application): AppDatabase {
        return Room.databaseBuilder(application, AppDatabase::class.java, "attendance.db")
            .addMigrations(AppDatabase.MIGRATION_1_2)
            .build()
    }

    @Singleton
    @Provides
    fun provideRecordDao(appDatabase: AppDatabase): RecordDao {
        return appDatabase.recordDao()
    }

    @Singleton
    @Provides
    fun provideOverworkDurationDao(appDatabase: AppDatabase): OverworkDurationDao {
        return appDatabase.overworkDurationDao()
    }
}